]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
Calendar: clean up code by always having an event source
authorGiovanni Campagna <gcampagna@src.gnome.org>
Mon, 4 Mar 2013 16:04:28 +0000 (17:04 +0100)
committerGiovanni Campagna <gcampagna@src.gnome.org>
Mon, 4 Mar 2013 17:59:30 +0000 (18:59 +0100)
Instead of sometimes having an event source and sometimes not, use
the empty event source when the session mode says the calendar is
disabled. This way, the code can assume an event source object and
avoid checks.

https://bugzilla.gnome.org/show_bug.cgi?id=641383

js/ui/calendar.js
js/ui/dateMenu.js

index 4606ed644406ffa8609acdfc9198b8c69e0f4fc2..b3eef9c76977424a1da15844be80d24a7fc5bb3c 100644 (file)
@@ -169,6 +169,10 @@ const EmptyEventSource = new Lang.Class({
 
     _init: function() {
         this.isLoading = false;
+        this.isDummy = true;
+    },
+
+    destroy: function() {
     },
 
     requestRange: function(begin, end) {
@@ -231,6 +235,7 @@ const DBusEventSource = new Lang.Class({
     _init: function() {
         this._resetCache();
         this.isLoading = false;
+        this.isDummy = false;
 
         this._initialized = false;
         this._dbusProxy = new CalendarServer();
@@ -256,6 +261,10 @@ const DBusEventSource = new Lang.Class({
         }));
     },
 
+    destroy: function() {
+        this._dbusProxy.run_dispose();
+    },
+
     _resetCache: function() {
         this._events = [];
         this._lastRequestBegin = null;
@@ -393,19 +402,11 @@ const Calendar = new Lang.Class({
     // @eventSource: is an object implementing the EventSource API, e.g. the
     // requestRange(), getEvents(), hasEvents() methods and the ::changed signal.
     setEventSource: function(eventSource) {
-        if (this._eventSource) {
-            this._eventSource.disconnect(this._eventSourceChangedId);
-            this._eventSource = null;
-        }
-
         this._eventSource = eventSource;
-
-        if (this._eventSource) {
-            this._eventSourceChangedId = this._eventSource.connect('changed', Lang.bind(this, function() {
-                this._update(false);
-            }));
-            this._update(true);
-        }
+        this._eventSource.connect('changed', Lang.bind(this, function() {
+            this._update(false);
+        }));
+        this._update(true);
     },
 
     // Sets the calendar to show a specific date
@@ -579,7 +580,7 @@ const Calendar = new Lang.Class({
             let button = new St.Button({ label: iter.getDate().toString() });
             let rtl = button.get_text_direction() == Clutter.TextDirection.RTL;
 
-            if (!this._eventSource)
+            if (this._eventSource.isDummy)
                 button.reactive = false;
 
             let iterStr = iter.toUTCString();
@@ -588,7 +589,7 @@ const Calendar = new Lang.Class({
                 this.setDate(newlySelectedDate, false);
             }));
 
-            let hasEvents = this._eventSource && this._eventSource.hasEvents(iter);
+            let hasEvents = this._eventSource.hasEvents(iter);
             let styleClass = 'calendar-day-base calendar-day';
 
             if (_isWorkDay(iter))
@@ -636,8 +637,7 @@ const Calendar = new Lang.Class({
         }
         // Signal to the event source that we are interested in events
         // only from this date range
-        if (this._eventSource)
-            this._eventSource.requestRange(beginDate, iter, forceReload);
+        this._eventSource.requestRange(beginDate, iter, forceReload);
     }
 });
 
@@ -655,16 +655,8 @@ const EventsList = new Lang.Class({
     },
 
     setEventSource: function(eventSource) {
-        if (this._eventSource) {
-            this._eventSource.disconnect(this._eventSourceChangedId);
-            this._eventSource = null;
-        }
-
         this._eventSource = eventSource;
-
-        if (this._eventSource) {
-            this._eventSourceChangedId = this._eventSource.connect('changed', Lang.bind(this, this._update));
-        }
+        this._eventSource.connect('changed', Lang.bind(this, this._update));
     },
 
     _addEvent: function(dayNameBox, timeBox, eventTitleBox, includeDayName, day, time, desc) {
@@ -681,9 +673,6 @@ const EventsList = new Lang.Class({
     },
 
     _addPeriod: function(header, begin, end, includeDayName, showNothingScheduled) {
-        if (!this._eventSource)
-            return;
-
         let events = this._eventSource.getEvents(begin, end);
 
         let clockFormat = this._desktopSettings.get_string(CLOCK_FORMAT_KEY);;
index 0529b3037ee1fad7c4349dc79eb599256d774127..54135603fb0070ec8b2ddfc0adfb4720bc7e7503 100644 (file)
@@ -177,8 +177,13 @@ const DateMenuButton = new Lang.Class({
     },
 
     _setEventSource: function(eventSource) {
+        if (this._eventSource)
+            this._eventSource.destroy();
+
         this._calendar.setEventSource(eventSource);
         this._eventList.setEventSource(eventSource);
+
+        this._eventSource = eventSource;
     },
 
     _sessionUpdated: function() {
@@ -187,7 +192,7 @@ const DateMenuButton = new Lang.Class({
         if (showEvents) {
             eventSource = new Calendar.DBusEventSource();
         } else {
-            eventSource = null;
+            eventSource = new Calendar.EmptyEventSource();
         }
         this._setEventSource(eventSource);
         this._setEventsVisibility(showEvents);